#/usr/bin/env python
#-*-coding:utf-8-*-



import requests
import json


from proto import topic_response_pb2

sess = requests.Session()
def get_topic(text):
    url = "http://127.0.0.1:19901/topic"
    data = {"text": text}
    res = sess.post(url, data=json.dumps(data))
    content = res.content

    pres = topic_response_pb2.TopicResponse()
    pres.ParseFromString(content)

    from google.protobuf.json_format import MessageToJson
    json_pres = MessageToJson(pres)
    obj_dict = json.loads(json_pres)
    return obj_dict

def get_lda_topic(text, url):
    data = {"text": text}
    res = sess.post(url, data=json.dumps(data))
    content = res.content

    pres = topic_response_pb2.TopicResponse()
    pres.ParseFromString(content)

    from google.protobuf.json_format import MessageToJson
    json_pres = MessageToJson(pres)
    obj_dict = json.loads(json_pres)
    return obj_dict

